package com.qf.openapi.web.master.controller;


import com.qf.openapi.web.master.entity.Customer;
import com.qf.openapi.web.master.service.CustomerService;
import com.qf.openapi.web.master.vo.CustomerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/costomer")
public class CustomerController {
    @Autowired
    CustomerService customerService;
    @RequestMapping("/login")
    public String login(@RequestBody CustomerVo customerVo , HttpSession session){
        String msg = "2";
        boolean falg = false;
        final String captcha = (String) session.getAttribute("captcha");
        final String captchar = customerVo.getCaptchar();
        final String username = customerVo.getUsername();
        final String password = customerVo.getPassword();
        if(captcha.equals(captchar)){
            final List<Customer> customers = customerService.selectAll();
            for (Customer customer : customers) {
                if(customer.getUsername().equals(username)&&customer.getPassword().equals(password)){
                    falg = true;
                }
            }
        }else{
             msg = "3";
        }
        if(falg){
            msg = "1";
        }
        return msg;
    }
}
